<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="">
    <title>404</title>
    <?php include_stylesheets() ?>
    <?php include_javascripts() ?>
  </head>
  <body>  
    <div class="container">
      <div class="header">
        <a class="navbar-brand navbar-logo pull-left" href="#" title=""></a>
      </div>
      <div class="register">
        <div class="register-form">
          <h1 class="title text-center">注册成功，请完善个人信息</h1>
          <form class="form-horizontal" action='<?php echo url_for('user/complete_info'); ?>' method='post'>
            <div class="form-group">
              <label for="" class="col-sm-2 control-label">头像设置：</label>
              <div class="col-sm-2">
                  <img src="<?php echo image_path('200x200.gif'); ?>" alt="" id="cover_pre" class="img-thumbnail" width="200" height="200">
              </div>
              <div class="clearfix"></div>
              <div class="col-sm-4 col-xs-offset-2">
                <input type="file" id="file_upload" name='cover' />
                <input type="hidden" id="cover_url" name='cover_url' value='' />
              </div>
            </div>
            <div class="form-group">
              <label for="" class="col-sm-2 control-label">您的昵称：</label>
              <div class="col-sm-4">
                <input type="text" class="form-control" id="" name="nickname" placeholder="">
              </div>
            </div>
            <div class="form-group">
              <label for="" class="col-sm-2 control-label">您的角色：</label>
              <?php foreach(User::$roles as $key => $value): ?>
              <div class="col-sm-1"><input type="radio" name="role" id="" value="<?php echo $key; ?>" checked><?php echo $value; ?></div>
              <?php endforeach; ?>
<!--              <div class="col-sm-1"><input type="radio" name="blankRadio" id="" value="option2"> 妈妈</div>
              <div class="clearfix"></div>
              <div class="col-sm-1 col-xs-offset-2"><input type="radio" name="blankRadio" id="" value="option3"> 爷爷</div>
              <div class="col-sm-1"><input type="radio" name="blankRadio" id="" value="option4"> 奶奶</div>
              <div class="col-sm-1"><input type="radio" name="blankRadio" id="" value="option5"> 外公</div>
              <div class="col-sm-1"><input type="radio" name="blankRadio" id="" value="option6"> 外婆</div>-->
            </div>
            <div class="form-group">
              <label for="" class="col-sm-2 control-label">您的地区：</label>
              <div class="col-sm-2">
                <select class="form-control" id="province" name="province">
                    <option value="0">请选择</option>
                  <?php foreach (User::getAllCitys() as $key=>$value): ?>
                  <option value="<?php echo $key; ?>"><?php echo $key; ?></option>
                  <?php endforeach; ?>
                </select>
              </div>
              <div class="col-sm-2">
                <select class="form-control" name="city" id="city">
                    <option value="0">请选择</option>
                </select>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">您的小孩：</label>
              <div class="col-sm-6" id="user_child">
                <?php foreach($user_childs as $child): ?>  
                <p class="form-control-static"><?php echo $child->getYear(); ?>年<?php echo $child->getMonth(); ?>月 <?php echo $child->getChildOld(); ?>岁 <?php echo $child->getSexToString(); ?>孩 
                    <a href="#" class="color-red" child_id="<?php echo $child->getId(); ?>"><i class="fa fa-plus-circle"></i>&nbsp;删除</a></p>
                <?php endforeach; ?>
              </div>
              <div class="clearfix"></div>
              <div class="col-sm-2 col-xs-offset-2">
                <select class="form-control" id="year">
                    <?php for($i=1960;$i<=date('Y');$i++): ?>
                  <option value="<?php echo $i;?>"><?php echo $i;?></option>
                  <?php endfor; ?>
                </select>
              </div>
              <div class="col-sm-2">
                <select class="form-control" name="month" id="month">
                  <?php for($i=1;$i<=12;$i++): ?>
                  <option value="<?php echo $i;?>"><?php echo $i;?></option>
                  <?php endfor; ?>
                </select>
              </div>
              <div class="col-sm-1"><input type="radio"  id="" name="sex" value="1" checked> 男</div>
              <div class="col-sm-1"><input type="radio"  id="" name="sex" value="0"> 女</div>
              <div class="col-sm-2">
                <p class="form-control-static"><a href="#" class="color-green" id="add_child"><i class="fa fa-minus-circle"></i>&nbsp;添加</a></p>
              </div>
            </div>
            <div class="form-group">
              <div class="col-sm-5 col-xs-offset-3">
                  <button type="submit" class="btn btn-green btn-lg btn-block">保存</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
    <div class="footer text-center">
      <div class="footer-nav"><span class="active">简体</span> &nbsp; <a href="#">繁体</a> &nbsp; <a href="#">English</a> &nbsp; <a href="#">常见问题</a></div>
      <div class="copyright">
        <div>&copy;2014 <a href="#">有学在线教育</a> 上海有学教育科技有限公司版权所有</div>
        <div><a href="#">京ICP证140465号</a> &nbsp; <a href="#">京ICP备13032407号-1</a> &nbsp; <a href="#">京公网安备 11010802013162</a></div>
      </div>
    </div>
      <script type='text/javascript'>
          
$(document).ready(function(){
    $("#province").change(function(){
        var p = $(this).val();
        $.get('<?php echo url_for('user/city'); ?>',{'key':p},function(msg){
            var citys = eval('('+msg+')');
            var options = '';
            for(var i in citys){
                options += '<option value="'+citys[i]+'">'+citys[i]+'</option>';
            }
            $("#city").html(options);
        })
    });
    
    $("#user_child").on('click','P > A',function(){
        var child_id = $(this).attr('child_id');
        var current_a = $(this);

        $.post('<?php echo url_for('user/del_child'); ?>',{'child_id':child_id},function(msg){
            var data =  eval('('+msg+')');
            if(data.success == 1){
                current_a.parents('P').remove();
            }
        });
        return false;
    });
    
    $("#add_child").click(function(){
        var year = $("#year").val();
        var month =  $("#month").val();
        var sex = $("input[name='sex']:checked").val();
        $.post('<?php echo url_for('user/add_child'); ?>',{'year':year,'month':month,'sex':sex},function(msg){
            var data = eval('('+msg+')');
            var html = '<p class="form-control-static">'+data.year+'年'+data.month+'月 '+data.old+'岁 '+data.sex+'孩 <a href="javascript:void(0);" child_id="'+data.id+'" class="color-red"><i class="fa fa-plus-circle"></i>&nbsp;删除</a></p>';
            $("#user_child").append(html);
        });
        return  false;
    });
    
});          
          
 $("#file_upload").uploadify({
        'formData'      : {'user_id' : '<?php echo $sf_user->getAttribute('user_id'); ?>'},
        height        : 30,
        swf           : '<?php echo image_path('uploadify.swf');?>',
        uploader      : '<?php echo url_for('user/cover');?>',
        width         : 120,
        'buttonText' : '点击上传',
        'method'   : 'post',
        'fileTypeExts' : '*.gif; *.jpg; *.png',
        'queueSizeLimit' : 1,
        onUploadSuccess : function(file, data, response) {
//            console.log('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
//            console.log(data);
            var d = eval('('+data+')');
            var error = d.error;
            
            if(error == 0){
                var url = d.url;
                $("#cover_url").val(url);
                $("#cover_pre").attr('src',url);
            }else{
                alert("文件上传出错，请重新检查！");
                return false;
            }
            
            return;
        }
    });
      </script>
  </body>
</html>